package com.example.dmc_android_sellbreakfast_ver1;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class addNewUserActivity extends Activity 
{
	Button btn_ok,btn_cancle;
	EditText edt_name,edt_number_room,edt_user,edt_pw;
	Database mDatabase;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setTitle("Add New");
		setContentView(R.layout.layout_addnew);
		init();
		handle();
	}

	private void init() {
		// TODO Auto-generated method stub
		btn_ok = (Button)findViewById(R.id.btn_ok);
		btn_cancle=(Button)findViewById(R.id.btn_cancle);
		edt_name=(EditText)findViewById(R.id.edt_name);
		edt_number_room=(EditText)findViewById(R.id.edt_number_room);
		edt_pw = (EditText)findViewById(R.id.edt_pw);
		edt_user = (EditText)findViewById(R.id.edt_user);
		mDatabase = new Database(this);
	}

	private void handle() {
		// TODO Auto-generated method stub
		btn_ok.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String name = edt_name.getText().toString();
				String NumberRoom = edt_number_room.getText().toString();
				String user = edt_user.getText().toString();
				String pw = edt_pw.getText().toString();
				mDatabase.open();
				mDatabase.Insert(user, pw, name, NumberRoom);
				mDatabase.close();
				Toast.makeText(v.getContext(), "register successful", 1000).show();
				finish();
			}
		});
		btn_cancle.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
	}

}
